package thinkingJava.chapter18;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static util.Print.*;

public class Logon implements Serializable {

	private Date date = new Date();
	private String username;
	private transient String password;

	public Logon(String name, String pwd) {
		username = name;
		password = pwd;
	}

	public String toString() {
		return "logon info : \n username : " + username
			+ "\n password : " + password
			+ "\n date : " + date;
	}
	public static void main(String[] args) throws Exception {
		Logon a = new Logon("Hulk", "MyLittlePony");
		print("Logon a = " + a);

		ObjectOutputStream o = new ObjectOutputStream(
				new FileOutputStream("Logon.out"));
		o.writeObject(a);
		o.close();

		TimeUnit.SECONDS.sleep(1);

		ObjectInputStream in = new ObjectInputStream(
				new FileInputStream("Logon.out"));
		a = (Logon) in.readObject();
		print("recover from inputstream");
		print("a = " + a);
	}
}
